Install Apache, php, mysql on Mac OS X

chris (2008-03-09 23:20:57)
4672 views
0 replies
I'm documenting this installation because it's the first time I have tried it on a mac. Hopefully it'll be pretty much the same as on other unices, so most of the process should be pretty familiar.

first installed macports from the dmg on this page: http://www.macports.org/install.php. Double click on the pkg file in the disk image and the installation will begin. Then follow these instructions to add parts of the /opt filesystem into your shell's search path.

I'm installing macports so that I can install wget. Wget makes it dead easy to download files off the web - then I'll use wget to grab the necessary source tarballs. When installing wget, macports strangely pulls in some other ports including expat, libiconv, ncurses, gettext, zlib, openssl and finally wget - here's why:

secondhalf-lm:~ clacy$ port
MacPorts 1.600
Entering interactive mode... ("help" for help, "quit" to quit)
[Users/clacy] > deps wget
wget has library dependencies on:
        openssl
        gettext
[Users/clacy] > deps gettext
gettext has library dependencies on:
        libiconv
        ncurses
        expat
[Users/clacy] > deps openssl
openssl has library dependencies on:
        zlib
[Users/clacy] > 

So port has followed, downloaded, extracted, configured, compiled and installed all the necessary dependencies for today's installation.

I like this.

The mysql OS X 10.4 disk image is available from here http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg. This will allow an easy installation of the mysql server binary for os x Tiger. To install the mysql server I just doubleclick the mysql-5.1.23-rc-osx10.4-i686.pkg file and accept the prompts. Now I can check that the new installation works:

secondhalf-lm:~ clacy$ sudo /usr/local/mysql/bin/mysqld_safe &
[1] 5359
secondhalf-lm:~ clacy$ 080308 13:11:29 mysqld_safe Logging to '/usr/local/mysql/data/secondhalf-lm.local.err'.
080308 13:11:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

secondhalf-lm:~ clacy$ /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.23-rc MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> 

Sweet. A working mysql server. Now let's compile Apache and PHP. First I download the php sources from a local mirror, then move them into /usr/src and pull in the apache sources too

secondhalf-lm:~ clacy$ sudo mv ./Desktop/php-5.2.5.tar.gz  /usr/src/.
secondhalf-lm:/usr/src clacy$ sudo wget http://archive.apache.org/dist/httpd/httpd-2.2.8.tar.gz
..etc

then compile as usual with the following commands:

secondhalf-lm:~ clacy$  cd /usr/src/
secondhalf-lm:~ clacy$  sudo tar -zxvf httpd-2.2.8.tar.gz
secondhalf-lm:~ clacy$  cd httpd-2.2.8
secondhalf-lm:~ clacy$  sudo ./configure \
--enable-module=most \
--enable-shared=max \
--enable-rewrite \
--enable-so
secondhalf-lm:~ clacy$  make
secondhalf-lm:~ clacy$  sudo make
secondhalf-lm:~ clacy$  sudo make install
secondhalf-lm:~ clacy$  cd ../
secondhalf-lm:~ clacy$  sudo wget http://www.zlib.net/zlib-1.2.3.tar.gz
secondhalf-lm:~ clacy$  sudo tar -zxvf zlib-1.2.3.tar.gz 
secondhalf-lm:~ clacy$  cd ../php-5.2.5
secondhalf-lm:~ clacy$  sudo ./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql \
--enable-pdo \
--with-zlib-dir=../zlib-1.2.3/ \
--with-pdo-mysql=/usr/local/mysql \
--with-mysql=/usr/local/mysql
secondhalf-lm:~ clacy$  sudo make
secondhalf-lm:~ clacy$  sudo make install

All that worked as expected and apache starts just fine, so no real surprises there. All that's required now is to reconfigure apache to load the php .so and to recognise the .php filetypes and all that stuff. I won't include that here, since it's standard configuration. The purpose of this document was just to note any mac-specific variations in building apache/php/mysql. It seems there are very few.
comment